package com.ww.springboot.boot.netty.client;

import io.netty.buffer.ByteBuf;

import io.netty.channel.ChannelHandler;

import io.netty.channel.ChannelHandlerContext;

import io.netty.channel.SimpleChannelInboundHandler;

import io.netty.util.CharsetUtil;

/**
 *  * @Date: 2020/6/1 11:12
 * <p>
 *  * @Description: 通用handler，处理I/O事件
 * <p>
 *  
 * @author ZH500
 */

@ChannelHandler.Sharable
public class HandlerClientHello extends SimpleChannelInboundHandler<ByteBuf> {

    /**
     * @Description  处理接收到的消息
     *         
     **/
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception {

        System.out.println("接收到的消息：" + byteBuf.toString(CharsetUtil.UTF_8));

    }

    /**
     * @Description  处理I/O事件的异常
     *         
     **/
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }

}
